﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Diagnostics;

namespace VehicleScale.DataAccess
{
    public class CommonDataAccess : BaseDataAccess, ICommonDataAccess
    {

        #region Properties

        /// <summary>
        /// Check connection property
        /// </summary>
        public bool CheckConnection
        {
            get
            {
                bool result = false;
                try
                {
                    using (DataClassesDataContext dataContext = new DataClassesDataContext(base.ConnectionString))
                    {
                        if (dataContext.DatabaseExists())
                        {
                            Common.Server = dataContext.Connection.DataSource;
                            Common.Database = dataContext.Connection.Database;
                            result = true;
                        }
                        else
                        {
                            dataContext.CreateDatabase();
                        }
                    }
                }
                catch (SqlException ex)
                {
                    Debug.WriteLine(ex.Message);
                }
                return result;
            }
        }

        #endregion

    }
}
